home *** CD-ROM | disk | FTP | other *** search
/ SGI Hot Mix 17 / Hot Mix 17.iso / HM17_SGI / research / examples / misc / sdf / hdf_info.pro < prev    next >
Text File  |  1997-07-08  |  8KB  |  230 lines

  1. pro HDF_info,filename,OUTFILE=outfile
  2. ; displays Raster,SD,MSDS and Vset information about filename,
  3. ; in tabular format
  4.  
  5. ;    Check for required number of input parameters
  6. if n_params() lt 1  then begin
  7.     printf,uid,'usage:  HDF_info,filename [,OUTFILE=outfile]'
  8.     printf,uid,"   ARGUMENTS : filename : string name of HDF file"
  9.     printf,uid,"      KEYWORDS:"
  10.     printf,uid,"        OUTFILE : filename for output information"
  11.     printf,uid,"            to be written to (optional)"
  12.     printf,uid,'   OUTPUTS: the HDF metadata for this file,'
  13.     printf,uid,'        always to the display, and possibly'
  14.     printf,uid,'        to the outfile specified'
  15.     printf,uid,"EXAMPLE:  HDF_info,'demo.hdf'"
  16.     printf,uid,'          will display the HDF metadata for this file'
  17.     return
  18. endif
  19. if not keyword_set(outfile) then uid=-1 else $
  20.    openw,uid,outfile,/get_lun
  21. ;
  22. ;    Create some useful formats
  23. ;
  24. F1='(" ",A,I4)'
  25. F2='("-----",A,A,"-----")'
  26. F3='("-----",A,"-----")'
  27. FI='(A24," ",A8," ",I6," ",I)'
  28. FS='(A24," ",A8," ",I6," ",A)'
  29. FF='(A24," ",A8," ",I6," ",F)'
  30. FD='(A24," ",A8," ",I6," ",D)'
  31. F4='(A24," ",A8," ",I6)'
  32. F5='(A24," ",A7," ",A7," ",A39)'
  33. F5L='(A24," ",A8," ",A8,"",A30)'
  34. F80='(80("-"))'
  35. F80E='(80("="))'
  36.  
  37. ;    Check that it is HDF !
  38. if HDF_ishdf(filename) ne 1 then begin
  39.     message,"File "+filename+" is not an HDF file."
  40. endif
  41.  
  42. ;      Open the HDF file readonly
  43.   fileid=HDF_OPEN(filename,/read)
  44.     printf,uid," *****BEGINNING OF HDF_INFORMATION***** "
  45.     printf,uid
  46.         printf,uid,FORMAT=F80E
  47.     printf,uid," FILENAME       : ",filename
  48.  
  49. ;    Get and report the number of free palettes.
  50.   numfpals=HDF_dfp_npals(filename)>0
  51.     printf,uid,FORMAT=F80E
  52.     printf,uid,"    # of free palettes = ",numfpals,FORMAT=F1
  53.  
  54. ;    Get the number of file ids and read them.
  55.   numid=HDF_number(fileid,tag=100)>0
  56.     printf,uid,FORMAT=F80E
  57.     printf,uid,"    # of file file ids = ",numid,FORMAT=F1
  58.     if numid ne 0 then begin
  59.     if numid eq 1 then begin
  60.         HDF_dfan_getfid,filename,fid,/first
  61.         printf,uid,"File Id",FORMAT=F3 & print,strcompress(string(fid))
  62.     endif else begin
  63.         printf,uid,"File Id",string(1),FORMAT=F2
  64.         HDF_dfan_getfid,filename,fid,/first & printf,uid,strcompress(string(fid))
  65.         for i=2,numid do  begin
  66.          printf,uid,"File Id",strtrim(string(i)),FORMAT=F2
  67.          HDF_dfan_getfid,filename,fid & printf,uid,strcompress(string(fid))
  68.         endfor
  69.     endelse
  70.     endif
  71.  
  72. ;    Get the number of file descriptions and read them.
  73.   numdesc=HDF_number(fileid,tag=101)>0
  74.     printf,uid,FORMAT=F80E
  75.     printf,uid,"    # of file descriptions = ",numdesc,FORMAT=F1
  76.     if numdesc ne 0 then begin
  77.     if numdesc eq 1 then begin
  78.         HDF_dfan_getfds,filename,desc,/first
  79.         printf,uid,"File Description",FORMAT=F3 & print,string(desc)
  80.     endif else begin
  81.          printf,uid,"File Description",string(1),FORMAT=F2
  82.         HDF_dfan_getfds,filename,desc,/first & printf,uid,string(desc)
  83.         for i=2,numdesc do  begin
  84.          printf,uid,"File Description",string(i),FORMAT=F2
  85.          HDF_dfan_getfds,filename,desc & printf,uid,string(desc)
  86.         endfor
  87.     endelse
  88.     endif
  89. ;
  90. ;       Get info on 8-bit images
  91. ;
  92.         HDF_DFR8_RESTART
  93.         NIMAGES=HDF_DFR8_NIMAGES(filename)
  94.         printf,uid,FORMAT=F80E
  95.         printf,uid,'      # of 8-bit images=',NIMAGES,FORMAT=F1
  96.         if NIMAGES gt 0 then begin
  97.            printf,uid
  98.            has_p=["No Palette. ","a Palette."]
  99.            for i = 0, NIMAGES -1 do begin
  100.                HDF_DFR8_GETINFO,filename,width,height,has_pal
  101.                printf,uid,i,width,height,has_p[has_pal],$
  102.                   FORMAT='(5X,"IMAGE # ",I3," is ",I4," by ",I3," Has ",A)'
  103.            endfor        
  104.         endif                
  105. ;
  106. ;       Get info on 24-bit images
  107. ;
  108.  
  109.         HDF_DF24_RESTART
  110.         NIMAGES=HDF_DF24_NIMAGES(filename)
  111.         printf,uid,FORMAT=F80E
  112.         printf,uid,'      # of 24-Bit images =',NIMAGES,FORMAT=F1
  113.         if NIMAGES gt 0 then begin
  114.            printf,uid
  115.            for i =0, NIMAGES-1 do begin
  116.            HDF_DF24_GETINFO,filename,width,height,interlace
  117.            printf,uid,'IMAGE #',i,' is ',width,' by ',height,'. Interlace = ',$
  118.                   interlace,FORMAT='(5X,A,I3,A,I4,A,I4,A,I1)'
  119.            endfor
  120.         endif
  121.  
  122. ;    Get the number of RIG groups in the file
  123.         numrig=HDF_number(fileid,tag=306)>0
  124.     printf,uid,FORMAT=F80E
  125.     printf,uid,"    # of RIG groups = ",numrig,FORMAT=F1
  126.     if numrig gt 0 then begin
  127.                 printf,uid
  128.         result=HDF_dfan_lablist(filename,306,reflist,RIGLABELS)
  129.         for i=0,n_elements(reflist)-1 do begin
  130.                     printf,uid,i,reflist[i],string(RIGLABELS[i]),$
  131.                      FORMAT='(5X,"RIG Group # ",I2,": Ref # ="'+$
  132.                       ',I3," : Label = ",A)'
  133.                 endfor
  134.     endif 
  135.         printf,uid,FORMAT=F80E
  136.  
  137. ;    Get the number of SDSs in the file
  138.  
  139. sd_id=HDF_SD_START(filename,/read)
  140. HDF_SD_FILEINFO,sd_id,nmfsds,nglobatts
  141. ;    Get the number of MFSDs in the file
  142.     printf,uid,"    # of MFSD = ",nmfsds,FORMAT=F1
  143.  
  144.     if nmfsds gt 0 then begin
  145.          printf,uid
  146.          printf,uid,FORMAT=F80
  147.          printf,uid,"          Information about MFHDF DataSets "
  148.          printf,uid,FORMAT=F80
  149.      printf,uid,"    NAME   IDL_Type   HDF_Type      Rank   Dimensions"
  150.          printf,uid,"---------  -------- ----------      ----  ------------"
  151.          printf,uid,"           ------------- Atrribute Info -------------"
  152.          printf,uid
  153.          FSD='(A10,"  ",A8,"  ",I4,"  ",I4)'
  154.      for i=0,nmfsds-1 do begin
  155.       sds_id=HDF_SD_SELECT(sd_id,i)
  156.           HDF_SD_GETINFO,sds_id,name=n,ndims=r,type=t,natts=nats,$
  157.                          hdf_type=h,unit=u
  158.           if r gt 0 then HDF_SD_GETINFO,sds_id,dims=dims else dims=0
  159.  
  160.           if r le 1 then FSD='(A10," ",A8," ",A12,3X,I4,3X,"[",I4,"] ",A)' $
  161.                    else FSD='(A10," ",A8," ",A12,3X,I4,3X,"["'+$
  162.                         STRING(r-1)+'(I4,","),I4,"] ",A)'
  163.           
  164.           printf,uid,n,t,h,r,dims,u,FORMAT=FSD
  165.           for j=0,nats-1 do begin
  166.         HDF_SD_ATTRINFO,sds_id,j,name=n,type=t,count=c,data=d,$
  167.                             hdf_type=h
  168.             
  169.               CASE t OF
  170.          'FLOAT':  FB='G)'
  171.                  'DOUBLE': FB='G)'
  172.                  'STRING': FB='A)'
  173.          ELSE:     FB='I)'
  174.             ENDCASE
  175.             
  176.         printf,uid,j+1,n,d[0],$
  177.              FORMAT='(11X,"Attribute => ",I3,2X,A13," = ",'+FB
  178.  
  179.        for k=1,n_elements(d)-1 do printf,uid,d[k],FORMAT='(45X,'+FB
  180.       endfor
  181.       HDF_SD_ENDACCESS,sds_id
  182.           printf,uid,FORMAT='(10X,70("_"))'
  183.      endfor
  184.     endif
  185.     printf,uid,FORMAT=F80E
  186.     printf,uid,"    # of Global Attributes ",nglobatts
  187.     if nglobatts gt 0 then begin
  188.          printf,uid
  189.      printf,uid,"------------------------------------------------"
  190.      printf,uid,'Name','Type','Elements','Value',FORMAT=F5L
  191.      printf,uid,FORMAT=F80
  192.      printf,uid
  193.      for i=0,nglobatts-1 do begin
  194.         HDF_SD_ATTRINFO,sd_id,i,name=n,type=t,count=c,data=d
  195.        if (t eq 'STRING' ) then printf,uid,strtrim(n),t,c,d[0,0],FORMAT=FS else $
  196.        if (t eq 'FLOAT' )  then printf,uid,strtrim(n),t,c,d[0,0],FORMAT=FF else $
  197.        if (t eq 'DOUBLE' ) then printf,uid,strtrim(n),t,c,d[0,0],FORMAT=FD else $
  198.         printf,uid,strtrim(n),t,c,d[0,0],FORMAT=FI
  199.      endfor
  200.     endif
  201.     HDF_SD_END,sd_id
  202.     printf,uid,FORMAT=F80E
  203.  
  204. ; START VGROUP SEARCH
  205. ;
  206.        lvgs=HDF_VG_LONE(fileid)
  207.         if lvgs[0] eq -1 then  begin
  208.             num_lone_vgroups=0 
  209.         printf,uid,"    # of Parent Vgroups",num_lone_vgroups
  210.             printf,uid,FORMAT=F80E
  211.         endif else begin
  212.             num_lone_vgroups=n_elements(lvgs)
  213.         printf,uid,"    # of Parent Vgroups",num_lone_vgroups
  214.             printf,uid,FORMAT=F80
  215.             printf,uid," Vgroup #   # of Members             Class                   Name " 
  216.           printf,uid,"---------  ---------------------------------------------------------"
  217.  for j=0,num_lone_vgroups-1 do begin 
  218.                  gid=HDF_VG_ATTACH(fileid,lvgs[j])
  219.                   HDF_VG_GETINFO,gid,NAME=gNAME,CLASS=gCLASS,NENTRIES=gNENTRIES
  220.                   printf,uid,j,gNENTRIES,gNAME,gCLASS,FORMAT='(2X,I3,10X,I3,8X,A20,2X,A20)'
  221.                  HDF_VG_DETACH,gid
  222.             endfor
  223.         printf,uid,'===================================================================='
  224.          endelse
  225.     printf,uid," *****END OF HDF_INFORMATION***** "
  226.     HDF_close,fileid
  227.  
  228.  if uid ne -1 then free_lun,uid
  229. end
  230.